package com.sccba.web.controller.yjcz;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.sccba.common.annotation.Log;
import com.sccba.common.core.controller.BaseController;
import com.sccba.common.core.domain.AjaxResult;
import com.sccba.common.core.domain.entity.SysUser;
import com.sccba.common.core.page.TableDataInfo;
import com.sccba.common.enums.BusinessType;
import com.sccba.common.utils.poi.ExcelUtil;
import com.sccba.system.service.ISysUserService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.sccba.emtbusiness.domain.YjczChannelInfo;
import com.sccba.emtbusiness.service.IYjczChannelInfoService;
import org.springframework.web.multipart.MultipartFile;

/**
 * 应用系统Controller
 * 
 * @author lichh
 * @date 2024-04-15
 */
@RestController
@RequestMapping("/yjcz/channel")
@CrossOrigin
public class YjczChannelInfoController extends BaseController
{
    @Autowired
    private IYjczChannelInfoService yjczChannelInfoService;

    @Autowired
    private ISysUserService sysUserService;

    /**
     * 查询应用系统列表
     */
    @PreAuthorize("@ss.hasPermi('yjcz:channel:list')")
    @GetMapping("/list")
    public TableDataInfo list(YjczChannelInfo yjczChannelInfo)
    {
        startPage();
        List<YjczChannelInfo> list = yjczChannelInfoService.selectYjczChannelInfoList(yjczChannelInfo);
        return getDataTable(list);
    }

    /**
     * 导出应用系统列表
     */
    @PreAuthorize("@ss.hasPermi('yjcz:channel:export')")
    @Log(title = "应用系统", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, YjczChannelInfo yjczChannelInfo)
    {
        List<YjczChannelInfo> list = yjczChannelInfoService.selectYjczChannelInfoList(yjczChannelInfo);
        ExcelUtil<YjczChannelInfo> util = new ExcelUtil<YjczChannelInfo>(YjczChannelInfo.class);
        util.exportExcel(response, list, "应用系统数据");
    }

    /**
     * 获取应用系统详细信息
     */
    @PreAuthorize("@ss.hasPermi('yjcz:channel:query')")
    @GetMapping(value = "/{pkId}")
    public AjaxResult getInfo(@PathVariable("pkId") Long pkId)
    {
        return success(yjczChannelInfoService.selectYjczChannelInfoByPkId(pkId));
    }

    /**
     * 新增应用系统
     */
    @PreAuthorize("@ss.hasPermi('yjcz:channel:add')")
    @Log(title = "应用系统", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody YjczChannelInfo yjczChannelInfo)
    {
        return toAjax(yjczChannelInfoService.insertYjczChannelInfo(yjczChannelInfo));
    }

    /**
     * 修改应用系统
     */
    @PreAuthorize("@ss.hasPermi('yjcz:channel:edit')")
    @Log(title = "应用系统", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody YjczChannelInfo yjczChannelInfo)
    {
        return toAjax(yjczChannelInfoService.updateYjczChannelInfo(yjczChannelInfo));
    }

    /**
     * 删除应用系统
     */
    @PreAuthorize("@ss.hasPermi('yjcz:channel:remove')")
    @Log(title = "应用系统", businessType = BusinessType.DELETE)
	@DeleteMapping("/{pkIds}")
    public AjaxResult remove(@PathVariable Long[] pkIds)
    {
        return toAjax(yjczChannelInfoService.deleteYjczChannelInfoByPkIds(pkIds));
    }



    /**
     * 查询应用系统列表
     */
    @GetMapping("/userList")
    public AjaxResult list(SysUser sysUser)
    {
        List<SysUser> userList = sysUserService.selectUserList(sysUser);
        return success(userList);
    }

    @PostMapping("/importTemplate")
    public void importTemplate(HttpServletResponse response)
    {
        ExcelUtil<YjczChannelInfo> util = new ExcelUtil<>(YjczChannelInfo.class);
        util.importTemplateExcel(response, "应用系统数据");
    }


    @Log(title = "应用系统管理", businessType = BusinessType.IMPORT)
    @PreAuthorize("@ss.hasPermi('yjcz:channel:import')")
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception
    {
        ExcelUtil<YjczChannelInfo> util = new ExcelUtil<>(YjczChannelInfo.class);
        List<YjczChannelInfo> channelInfoList = util.importExcel(file.getInputStream());
        String operName = getUsername();
        String message = yjczChannelInfoService.importChannel(channelInfoList, updateSupport, operName);
        return success(message);
    }
}
